#include <stdio.h>

int main(){
    unsigned long long base, power, moder;
    scanf("%llu %llu %llu", &base, &power, &moder);
    unsigned long long result = 1;
    while (power) {
        if (power & 1) {
            result = (result * base) % moder;
        }
        base = (base * base) % moder;
        power >>= 1;
    }
    printf("%llu\n", result);

}